package com.zbl.zblproject.core.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zbl.zblproject.core.entity.UserAddress;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author youlanqiang
 * @version 1.0
 * @date 2018/10/17
 */
@Repository
public interface UserAddressMapper extends BaseMapper<UserAddress> {

    @Select("SELECT address FROM  zbl_user_address WHERE user_id = #{userId} ")
    String selectAddressByUserId(@Param("userId") int userId);

    @Select("SELECT * FROM  zbl_user_address WHERE user_id = #{userId} AND is_del = 0 ")
    List<UserAddress> selectAddressesByUserId(@Param("userId") int userId);

    @Select("SELECT * FROM zbl_user_address WHERE address = #{value} ")
    UserAddress selectAddressByAddressValue(@Param("value") String value);

    @Select("SELECT * FROM zbl_user_address WHERE user_id = #{userId} LIMIT 1")
    UserAddress selectOneByUserId(@Param("userId") int userId);

    @Select("SELECT a.address_id,a.consignee,a.mobile,CONCAT((select region_name from zbl_region b where b.region_id=a.province),'省',(select region_name from zbl_region b where b.region_id=a.city),'市',(select region_name from zbl_region b where b.region_id=a.district),address) as address FROM  zbl_user_address a WHERE a.user_id = #{userId} AND a.is_del = 0 ")
    List<UserAddress> selectAddressesByUserIds(@Param("userId") int userId);
}
